package com.earnings.okhttputils.utils.ui.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.earnings.R;
import com.earnings.okhttputils.utils.OkHttp.OkHttpUtils;
import com.earnings.okhttputils.utils.UrlConstant.YUrlAddress;
import com.earnings.okhttputils.utils.adapter.LoveDetailAdapter;
import com.earnings.okhttputils.utils.bean.LoveDetailData;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.https.HttpArrayCallback;
import com.earnings.okhttputils.utils.https.HttpMap;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 爱心明细
 * Created by Administrator on 2017/5/9 0009.
 */

public class LoveDetailActivity extends GodLeftHandBaseActivity {
    private RecyclerView recyclerview;
    private LoveDetailAdapter adapter;

    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_detail;
    }

    @Override
    protected void init() {
        setTop();
        recyclerview = getView(R.id.recyclerview);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) recyclerview.getLayoutParams();
        params.setMargins(0, 20, 0, 0);
        recyclerview.setLayoutParams(params);
        adapter = new LoveDetailAdapter(R.layout.item_detail);
        setRecyclerViewLayoutManager(R.id.recyclerview, new LinearLayoutManager(this)).setAdapter(adapter);
        Map<String, String> map = new HttpMap(this);
        map.put("p", "1");
        OkHttpUtils.post().url(YUrlAddress.LOVE_DETAIL_URL).params(map).build().execute(new HttpArrayCallback<LoveDetailData>(this) {

            @Override
            public void onSuccess(List<LoveDetailData> object, String msg) {
                Collections.reverse(object);
                adapter.setDatas(object);

            }

            @Override
            public void onFail(int code, String msg) {

            }
        });
    }

    private void setTop() {
        setTitle("爱心明细");
        setTopViewBackgroundResource(getResources().getColor(R.color.style));
        title_tv.setTextColor(getResources().getColor(R.color.white));
        back_view.setImageResource(R.mipmap.nav_back02);
    }
}